<template>
	<view class="register">
		<view class="input">
			<view class="name">
				<view>昵称</view>
				<uni-easyinput v-model="name" maxlength="11" confirmType="下一步" focus placeholder="请输入昵称"></uni-easyinput>
				<!-- errormessage -->
			</view>
			<view class="userName">
				<view>用户名</view>
				<uni-easyinput v-model="userName" maxlength="11" confirmType="下一步" focus placeholder="请输入用户名"></uni-easyinput>
				<!-- errormessage -->
			</view>
			<view class="password">
				<view>密码</view>
				<uni-easyinput type="password" v-model="password" maxlength="11" placeholder="请输入密码"></uni-easyinput>
			</view>
		</view>
		<view class="button">
			<button type="default" hover-class="btn2" @click="register(name,userName,password)">注册</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				userName: '',
				password: ''
			}
		},
		methods: {
			register(name,userName,password) {
				if(userName === '' || password === ''){
					uni.showToast({
						title: '用户名或密码不能为空'
					})
				}
				else if(name === ''){
					uni.showToast({
						title: '昵称不能为空'
					})
				}
				else{
					uni.request({
						url: 'http://www.yingke.com/Index/register',
						method: 'POST',
						data: {
							user_name: userName,
							pwd: password,
							name: name
						},
						success: (res) => {
							uni.showToast({
								icon: 'none',
								title: res.data.msg,
							});
							if(res.data.code===0)
								setTimeout(() => {
									uni.hideToast();
									//关闭提示后跳转
									uni.navigateBack()
								},1500)
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.register{
		margin: 10px 10px;
		font-size: 15px;
		.input{
			.userName{
				
			}
			.password{
				
			}
		}
		.button{
			margin-top: 20px;
			display: flex;
			button{
				width: 95%;
				background-color: #d81e06;
				color: #fff;
			}
			.btn2{
				background-color: #710e03;
			}
		}
	}
</style>
